package com.ruoyi.project.inspection.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.inspection.domain.ViProcessData;
import com.ruoyi.project.inspection.service.IViProcessDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检测进度模板Controller
 *
 * @author ruoyi
 * @date 2020-07-17
 */
@RestController
@RequestMapping("/inspection/data")
public class ViProcessDataController extends BaseController {
    @Autowired
    private IViProcessDataService viProcessDataService;

    /**
     * 查询检测进度模板列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViProcessData viProcessData) {
        startPage();
        List<ViProcessData> list = viProcessDataService.selectViProcessDataList(viProcessData);
        return getDataTable(list);
    }

    /**
     * 导出检测进度模板列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:data:export')")
    @Log(title = "检测进度模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ViProcessData viProcessData) {
        List<ViProcessData> list = viProcessDataService.selectViProcessDataList(viProcessData);
        ExcelUtil<ViProcessData> util = new ExcelUtil<ViProcessData>(ViProcessData.class);
        return util.exportExcel(list, "data");
    }

    /**
     * 获取检测进度模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(viProcessDataService.selectViProcessDataById(id));
    }

    /**
     * 新增检测进度模板
     */
    @PreAuthorize("@ss.hasPermi('inspection:data:add')")
    @Log(title = "检测进度模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViProcessData viProcessData) {
        return toAjax(viProcessDataService.insertViProcessData(viProcessData));
    }

    /**
     * 修改检测进度模板
     */
    @PreAuthorize("@ss.hasPermi('inspection:data:edit')")
    @Log(title = "检测进度模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViProcessData viProcessData) {
        return toAjax(viProcessDataService.updateViProcessData(viProcessData));
    }

    /**
     * 删除检测进度模板
     */
    @PreAuthorize("@ss.hasPermi('inspection:data:remove')")
    @Log(title = "检测进度模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(viProcessDataService.deleteViProcessDataByIds(ids));
    }
}
